package com.example.healthmanagement.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.healthmanagement.pojo.ChildDietaryRecords;
import com.example.healthmanagement.pojo.Childinformationtable;
import com.example.healthmanagement.pojo.Foodinfo;
import com.example.healthmanagement.pojo.VO.aVo;
import com.example.healthmanagement.pojo.VO.ecommendVo;
import com.example.healthmanagement.service.ChildDietaryRecordsService;
import com.example.healthmanagement.service.ChildinformationtableService;
import com.example.healthmanagement.service.FoodinfoService;
import com.example.healthmanagement.utils.formulaUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * <p>
 * 用户的食物 前端控制器
 * </p>
 *
 * @author chen
 * @since 2024-03-08
 */
@RestController
@RequestMapping("/childdietaryrecords")
public class ChildDietaryRecordsController {
    @Autowired
    ChildDietaryRecordsService foodinfoService;
    @Autowired
    FoodinfoService foodinfoServicse;
    @Autowired
    ChildinformationtableService childinformationtableService;
    @GetMapping("")
    public List<ChildDietaryRecords> getSportRecords(ChildDietaryRecords foodinfo) {
        List<ChildDietaryRecords> objectList = foodinfoService.list(new LambdaQueryWrapper<ChildDietaryRecords>().eq(foodinfo.getFood() != null, ChildDietaryRecords::getFood, foodinfo.getFood())

        );
        return objectList;
    }
    @PostMapping("")
    public boolean saveSportRecords(@RequestBody ChildDietaryRecords foodinfo) {

        return foodinfoService.save(foodinfo);
    }
    @PutMapping ("")
    public boolean updateSportRecords(@RequestBody ChildDietaryRecords foodinfo) {

        return foodinfoService.updateById(foodinfo);
    }
    @DeleteMapping  ("/{id}")
    public boolean DeleteSportRecords(@PathVariable("id") Long[] id) {

        return foodinfoService.removeByIds(Arrays.asList(id));
    }

    @PostMapping("/getsuggest")
    public List<Foodinfo>  getsuggest(@RequestParam List<String> strings){
        //获取食物的分类
        LambdaQueryWrapper<Foodinfo> recordsLambdaQueryWrapper=new LambdaQueryWrapper<>();
        recordsLambdaQueryWrapper.in(false,Foodinfo::getFoodname,strings);
        List<Foodinfo> foodinfos = foodinfoServicse.list(recordsLambdaQueryWrapper);

       return foodinfos;
    }
    /**
     * bmi判断用户是否健康,推荐饮食
     */

    @PostMapping("/getHealth")
    public List<Foodinfo>  getsuggest(aVo a){
      //获取小孩一天需要的热量
        Childinformationtable serviceOne = childinformationtableService.getOne(new LambdaQueryWrapper<Childinformationtable>().eq(Childinformationtable::getUserID, a.getUid()));
        double heat = formulaUtil.getHeat(serviceOne, serviceOne.getSex());

//        String bmi1 = formulaUtil.getBmi(bmi);
        List<Foodinfo> foodinfos=new ArrayList<>();
        //偏胖
          if (a.getBmi()>18){
              foodinfos = foodinfoServicse.list(new LambdaQueryWrapper<Foodinfo>().ge(Foodinfo::getEnergy, 99));
          }else {
              foodinfos = foodinfoServicse.list(new LambdaQueryWrapper<Foodinfo>().gt(Foodinfo::getEnergy, 100));
          }

        //运动方案
      String recommendExercise = formulaUtil.recommendExercise(serviceOne.getAge());


        return foodinfos;
    }
    /**
     * bmi判断
     */

    @PostMapping("/getRecommend")
    public List<Foodinfo>  getrecommend( ecommendVo ecommendVo){
        return null;
    }

}

